//初始化文本框的事件
function initEvent()
{
	var allInput = document.getElementsByTagName("input");
	for(var i=0 ; i<allInput.length ; i++)
	{
		if(allInput[i].type=='text'){
		
     	if(window.addEventListener){ // Mozilla, Netscape, Firefox   
		     allInput[i].addEventListener('onfocus', fieldFocus(), false);   
		     allInput[i].addEventListener('onblur', fieldBlur(), false);   
		 } else { // IE   
		     allInput[i].attachEvent('onfocus', fieldFocus);   
		     allInput[i].attachEvent('onblur',  fieldBlur);   
		 }  
     	
		}
	}
}
//得到焦点的事件
function fieldFocus()
{
	var serE=event.srcElement;
	serE.style.backgroundColor="white";
	var tip = serE.getAttribute("name");
	var splitTip = tip.split('.');
	if(splitTip[0]=="student")
	{
		setStudentTip(tip);
	}else if(splitTip[0]=="teacher")
	{
		setTeacherTip(tip);
	}
	
}
//失去焦点的事件
function fieldBlur()
{
	var serE = event.srcElement;
	serE.style.backgroundColor="#999999";
	var tipName =  serE.getAttribute("name");
	clearTip(tipName);
}
function clearTip(tipName)
{
	var splitTip = tipName.split('.');
	if(splitTip[0]=="student")
	{
		document.getElementById("studentTip").innerHTML="";
	}else if(splitTip[0]=="teacher")
	{
		document.getElementById("teacherTip").innerHTML="";
	}
}
function setStudentTip(name)
{
	var sTop = document.getElementById("studentTip");
	if(name=="student.studentNum")
	{
		sTop.innerHTML="学号为8位数字";
	}else if(name=="student.fixedTelephone")
	{
		sTop.innerHTML="请以区号开口,示例:0574-86545565";
	}
}
function setTeacherTip(name)
{
	var sTop = document.getElementById("teacherTip");
	if(name=="teacher.teacherNum")
	{
		sTop.innerHTML="教工号为6到8位数字";
	}else if(name=="teacher.fixedTelephone")
	{
		sTop.innerHTML="请以区号开口,示例:0574-86545565";
	}
}
function checkStudent(){
	var sTop = document.getElementById("studentTip");
	//学号
	var sNum = document.getElementById("sNum");
	var patrn=/^[0-9]{8}$/;
	if(!patrn.exec(sNum.value))
	{
		sTop.innerHTML="学号必须为8位的数字";
		return false;
	}
	//姓名
	var sName = document.getElementById("sName");
	if(sName.value==""||sName.value==null)
	{
		sTop.innerHTML="姓名不能为空";
		return false;
	}
	//专业编号
	var sProfessional = document.getElementById("sProfessional");
	patrn = /^\d+$/;
	if(!patrn.exec(sProfessional.value))
	{
		sTop.innerHTML="专业编号必须为数字";
		return false;
	}
	//年纪
	var grade = document.getElementById("grade");
	if(grade.value==""||grade.value==null)
	{
		sTop.innerHTML="年纪不能为空";
		return false;
	}
	//班级
	var classes = document.getElementById("classes");
	if(classes.value==""||classes.value==null)
	{
		sTop.innerHTML="班级不能为空";
		return false;
	}
	//手机
	var sTelephone = document.getElementById("sTelephone");
	patrn =/^1[3,5]\d{9}$/;
	if(!patrn.exec(sTelephone.value))
	{
		sTop.innerHTML="请输入手机的正确格式";
		return false;
	}
	//邮箱
	var sEmail = document.getElementById("sEmail");
	patrn =/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
	if(!patrn.exec(sEmail.value))
	{
		sTop.innerHTML="请输入邮箱的正确格式";
		return false;
	}
	//固定电话
	var sFixed = document.getElementById("sFixed");
	patrn =/^0\d{3}\d?-\d{7}\d?/;
	if(!patrn.exec(sFixed.value))
	{
		sTop.innerHTML="请输入固定电话的正确格式";
		return false;
	}
	return true;
}
function checkTeacher(){
	var sTop = document.getElementById("teacherTip");
	//教工号
	var tNum = document.getElementById("tNum");
	var patrn=/^[0-9]{6,8}$/;
	if(!patrn.exec(tNum.value))
	{
		sTop.innerHTML="教工号必须为6到8位的数字";
		return false;
	}
	//姓名
	var tName = document.getElementById("tName");
	if(tName.value==""||tName.value==null)
	{
		sTop.innerHTML="姓名不能为空";
		return false;
	}
	//研究所编号
	var tInstitute = document.getElementById("tInstitute");
	patrn = /^\d+$/;
	if(!patrn.exec(tInstitute.value))
	{
		sTop.innerHTML="研究所编号必须为数字";
		return false;
	}
	//职称
	var tTitle = document.getElementById("tTitle");
	if(tTitle.value==""||tTitle.value==null)
	{
		sTop.innerHTML="职称不能为空";
		return false;
	}
	//研究方向
	var reaserch = document.getElementById("reaserch");
	if(reaserch.value==""||reaserch.value==null)
	{
		sTop.innerHTML="研究方向不能为空";
		return false;
	}
	//手机
	var tTelephone = document.getElementById("tTelephone");
	patrn =/^1[3,5]\d{9}$/;
	if(!patrn.exec(tTelephone.value))
	{
		sTop.innerHTML="请输入手机的正确格式";
		return false;
	}
	//邮箱
	var tEmail = document.getElementById("tEmail");
	patrn =/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
	if(!patrn.exec(tEmail.value))
	{
		sTop.innerHTML="请输入邮箱的正确格式";
		return false;
	}
	//固定电话
	var tFixed = document.getElementById("tFixed");
	patrn =/^0\d{3}\d?-\d{7}\d?/;
	if(!patrn.exec(tFixed.value))
	{
		sTop.innerHTML="请输入固定电话的正确格式";
		return false;
	}
	return true;
}